import 'pigeons_model/pigeons_model.dart';

/// SessionInvalid 工具类
class SessionInvalidUtils {
  /// 创建 SessionInvalidResult
  static SessionInvalidResult createResult({
    required String timestamp,
    required String message,
  }) {
    return SessionInvalidResult(
      timestamp: timestamp,
      message: message,
    );
  }

  /// 创建默认的 SessionInvalidResult
  static SessionInvalidResult createDefaultResult() {
    return SessionInvalidResult(
      timestamp: DateTime.now().toIso8601String(),
      message: '会话已失效，请重新登录222',
    );
  }

  /// 格式化时间戳
  static String formatTimestamp(String timestamp) {
    try {
      final dateTime = DateTime.parse(timestamp);
      return '${dateTime.year}-${dateTime.month.toString().padLeft(2, '0')}-${dateTime.day.toString().padLeft(2, '0')} ${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')}:${dateTime.second.toString().padLeft(2, '0')}';
    } catch (e) {
      return timestamp;
    }
  }

  /// 获取结果信息
  static String getResultInfo(SessionInvalidResult result) {
    return '时间: ${formatTimestamp(result.timestamp)}\n消息: ${result.message}';
  }
}
